package com.net.test.controller;

import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.net.test.service.HaService;
import com.net.test.service.LolService;
import com.net.test.vo.HaVO;

@Controller
public class HaController {
	
	private static final Logger logger = LoggerFactory.getLogger(LolService.class);
	@Autowired
	HaService haService;
	
	@RequestMapping(value = "/haList.ncb", method = {RequestMethod.GET,RequestMethod.POST})
    public String HaList(Locale locale, Model model) throws Exception {		
		logger.info("Welcome home! The client locale is {}.", locale);
		
		List<HaVO> list = (List<HaVO>)haService.selectData("testMapper.haSelect");
		
		model.addAttribute("list",list);
		
		
		return "haList";		
	}
	@RequestMapping(value = "/haWrite.ncb", method = {RequestMethod.GET, RequestMethod.POST})
	public String HaWrite(Locale locale, Model model) throws Exception{
		
		return "haWrite";
	}
	@RequestMapping(value = "/haInsert.ncb", method = {RequestMethod.GET, RequestMethod.POST})
	public String HaInsert(Locale locale, Model model, HttpServletRequest request) throws Exception{
		
		HaVO insert = new HaVO();
		String title = request.getParameter("title");
		String contents = request.getParameter("contents");
		
		insert.setBoard_Title(title);
		insert.setBoard_Contents(contents);
		
		int result = haService.insertData("testMapper.insertBoard", insert);
		
		List<HaVO> list = (List<HaVO>)haService.selectData("testMapper.haSelect");
		
		model.addAttribute("list", list);
		
		return "haList";
		
	}
	

}
